package mysql

import "project/pkg/models"

func (m Mysql) ClassCheckExistByID(id string) (exist bool, info *models.ClassInfo, err error) {
	var count int64
	exist = false
	err = m.db.Table("class_info").Where("id = ?", id).Count(&count).Error
	if err != nil {
		return
	}
	if count > 0 {
		exist = true
		err = m.db.Table("class_info").Where("id = ?", id).First(&info).Error
		if err != nil {
			return
		}
	}
	return
}
func (m Mysql) ClassCheckExistByName(name string) (exist bool, info *models.ClassInfo, err error) {
	var count int64
	exist = false
	err = m.db.Table("class_info").Where("name = ?", name).Count(&count).Error
	if err != nil {
		return
	}
	if count > 0 {
		exist = true
		err = m.db.Table("class_info").Where("name = ?", name).First(&info).Error
		if err != nil {
			return
		}
	}
	return
}
func (m Mysql) ClassUpdateInfoBuID(val *models.ClassInfo) (err error) {
	return m.db.Table("class_info").Save(&val).Error
}
